-----------------------------------------------------------
--- /shared/timer_class.lua                             ---
--- Part of openFrame project                           ---
--- Written by Orange                                   ---
--- Lately edited in revision number 11 by Orange       ---
--- Licensed under BSD licence                          ---
-----------------------------------------------------------

-- Title: Utility functions

--	Function: removeColorCoding
--	This function removes color tags from text/nicknames etc.
--
--	Returns:
--		Returns string without color codes
function removeColorCoding ( name )
	return type(name)=='string' and string.gsub ( name, '#%x%x%x%x%x%x', '' ) or name
end

--	Function: isServer
--	This function detects if the script is running serverside.
--
--	Returns:
--		Returns true if the side is server, false otherwise.
function isServer()
				return triggerClientEvent ~= nil	end


--	Function: isClient
--	This function detects if the script is running clientside.
--
--	Returns:
--		Returns true if the side is client, false otherwise.
function isClient()	
			return triggerServerEvent ~= nil	end
			
ResourceRoot = getResourceRootElement(getThisResource())

function findPlayerByName (playerPart)
    for i,v in ipairs (getElementsByType ("player")) do
        if (string.find(string.lower(getPlayerName(v)),string.lower(playerPart))) then
        	return v; 
        end
    end
    return false;
end

function math.round(number, decimals, method)
    decimals = decimals or 0
    local factor = 10 ^ decimals
    if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
    else return tonumber(("%."..decimals.."f"):format(number)) end
end

_md5 = md5

function md5(text)
	return string.lower(_md5(text));
end

null = "NULL"

function table.size(tab)
    local length = 0
    for _ in pairs(tab) do length = length + 1 end
    return length
end

function showHUD(state)
	showPlayerHudComponent("ammo", state)
	showPlayerHudComponent("area_name", state)
	showPlayerHudComponent("armour", state)
	showPlayerHudComponent("breath", state)
	showPlayerHudComponent("clock", state)
	showPlayerHudComponent("health", state)
	showPlayerHudComponent("money", state)
	showPlayerHudComponent("radar", state)
	showPlayerHudComponent("vehicle_name", state)
	showPlayerHudComponent("weapon", state)
	showChat(state)
end

function showAlternateHUD(state)
	showPlayerHudComponent("radar", state)
	showPlayerHudComponent("vehicle_name", state)
	showChat(state)
end

function string.explode(self, separator)
    --Check("string.explode", "string", self, "ensemble", "string", separator, "separator")
 
    if (#self == 0) then return {} end
    if (#separator == 0) then return { self } end
 
    return loadstring("return {\""..self:gsub(separator, "\",\"").."\"}")()
end